package com.bbx.taxi.client.Task;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;

import com.bbx.api.sdk.SDK;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialTime;
import com.bbx.api.sdk.model.passanger.SvconfigBuild;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Official_UtilsTimeNet;
import com.bbx.taxi.client.Task.BaseAsyncTask;

/** 
 * @Path com.bbx.taxi.client.Task.MyServerTimeTask.java
 * @Author 严旭文
 * @Date 2016-3-1 下午3:09:10
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 获取服务器时间
 */
public class MyServerTimeTask {
	private Context context;
	private ServerTimeTask mServerTimeTask;
	public static MyServerTimeTask instance;
	public static MyServerTimeTask getInstance(Context context) {
		instance = new MyServerTimeTask( context);
		return instance;
	}
	public MyServerTimeTask(Context context) {
		this.context=context;
		getTime();
	}
	private void getTime() {
		SvconfigBuild mSvconfigBuild = new SvconfigBuild(context);
		mSvconfigBuild.version=1;
		mServerTimeTask = new ServerTimeTask(context, mSvconfigBuild);
		mServerTimeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	public class ServerTimeTask extends BaseAsyncTask {

		private SvconfigBuild mSvconfigBuild;

		public ServerTimeTask(Context context, SvconfigBuild mSvconfigBuild) {
			super(context, false,0);
			this.mSvconfigBuild = mSvconfigBuild;
		}

		@Override
		protected Object doInBackground(Object... params) {
			String json = new JsonBuild().setModel(mSvconfigBuild)
					.getJson();
			return new Official_UtilsTimeNet(context,json);
		}

		@Override
		public void onSuccess(Object object) {
			if(object!=null){
				OfficialTime mOfficialTime=(OfficialTime)object;
				SDK.GetSDK().mClient.setTime(mOfficialTime.getTime());
			}
		}

		@Override
		public void onFailed(int status, String msg) {
		}
	}
}
